<?php
/**
 * Created by DRCOM.
 * User: GZX
 * Datetime: 2021-07-26 8:57
 */

namespace app\api\controller;


class Lottery
{

    public function hk6()
    {
        debug('begin');
        $file = APP_PATH.'hk6';
        $url = "http://vip.jy365p.com/K2610d23d41cd32/p/1.json";
        $contents = file_get_contents($url);

        debug('end');
        $running = debug('begin', 'end', 3);
        $data = json_decode($contents, true);
        $data['XGLHC'][0]['running_time'] = $running;
        $int = db('lottery')->strict(true)->insertAll($data['XGLHC'][0],true);

        if (isset($data['XGLHC'][0]['code'])) {
            $title = $data['XGLHC'][0]['issue'];
            $msg = $data['XGLHC'][0]['code'];
            if (file_exists($file)) {
                $hk6 = file_get_contents($file);
                if ($hk6 == $msg) {
                    die('opened:' . $msg);
                }
            }
            echo 'send:' . $msg;

            $mails = [
                '13719205474@139.com',
                '18318025813@139.com',
            ];
            $mails = implode(';', $mails);
            $obj = \app\common\library\Email::instance();
            $code = explode("+",$msg);
            $tm = $code[1];
            $mz = explode(',',$code[0]);

            $result = $obj
                ->to($mails)
                // ->subject("第{$title}期:")
                ->subject($msg)
                ->message($msg)
                ->send();

            }

            if ($result) {
                file_put_contents($file, $msg);
                echo "\tsuccess";
            }
        }

    
    
    
        

    
    


}